package 最少翻转次数使二进制矩阵回文I3239;

public class Solution {
    public int minFlips(int[][] grid) {
        int countX = 0;
        int county = 0;
        for (int i = 0; i < grid.length; i++) {
            int left = 0;
            int right = grid[i].length - 1;
            while (left < right) {
                if(grid[i][left] != grid[i][right]) {
                    countX++;
                }
                left++;
                right--;
            }
        }
        for (int i = 0; i < grid[0].length; i++) {
            int left = 0;
            int right = grid.length - 1;
            while (left < right) {
                if(grid[left][i] != grid[right][i]) {
                    county++;
                }
                left++;
                right--;
            }
        }
        return Math.min(county, countX);
    }
}
